package com.cloud.mall.member.controller;

import com.cloud.mall.base.BaseResponse;
import com.cloud.mall.member.domain.MemberBrandAttention;
import com.cloud.mall.member.service.MemberAttentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员关注品牌管理Controller
 * Created by macro on 2018/8/2.
 */
@RestController
@Api(description = "会员关注品牌管理")
@RequestMapping("/member/attention")
public class MemberAttentionController {
    @Autowired
    private MemberAttentionService memberAttentionService;
    @ApiOperation("添加品牌关注")
    @PostMapping("/add")
    public BaseResponse add(@RequestBody MemberBrandAttention memberBrandAttention) {
        int count = memberAttentionService.add(memberBrandAttention);
        if(count<=0){
            return BaseResponse.setResultError();
        }
            return BaseResponse.setResultSuccess(count);

    }

    @ApiOperation("取消关注")
    @PostMapping("/delete")
    public BaseResponse delete(Long memberId, Long brandId) {
        int count = memberAttentionService.delete(memberId,brandId);
        if(count<=0){
            return BaseResponse.setResultError();
        }
        return BaseResponse.setResultSuccess(count);
    }

    @ApiOperation("显示关注列表")
    @GetMapping("/list/{memberId}")
    public BaseResponse<List<MemberBrandAttention>> list(@PathVariable Long memberId) {
        List<MemberBrandAttention> memberBrandAttentionList = memberAttentionService.list(memberId);
        return BaseResponse.setResultSuccess(memberBrandAttentionList);
    }
}
